package com.tbit.main.controller;

import com.tbit.main.constant.ResponseCode;
import com.tbit.main.exception.BaseException;
import com.tbit.main.pojo.Country;
import com.tbit.main.service.CountryService;
import com.tbit.main.util.OutputUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 国家手机号
 *
 * @author LMY
 * @create 2021-05-27 10:56
 */
@RestController
@RequestMapping("/cuntry")
public class CountryController {
    @Autowired
    private CountryService countryService;

    /**
     * 查询所有
     *
     * @param session
     * @param request
     * @param response
     */
    @RequestMapping("/query")
    public void getFee(HttpSession session, HttpServletRequest request,
                       HttpServletResponse response) {
        Map<String, Object> map = new HashMap<String, Object>();

        try {

            List<Country> list = countryService.query();

            map.put(ResponseCode.RET, ResponseCode.SUCC);
            map.put(ResponseCode.DATA, list);
        } catch (BaseException e) {
            ResponseCode.printException(map, e);
        }

        OutputUtil.renderText(request, response, map);
    }
}
